package com.team3.ecommerce.controller;


import com.team3.ecommerce.domain.UserInfo;
import com.team3.ecommerce.service.UserAuthService;
import com.team3.ecommerce.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.security.Principal;

@Controller
public class IndexController {
    @Autowired
    private UserAuthService userAuthService;
    @Autowired
    private UserInfoService userInfoService;

    @GetMapping("/index")
    public String indexPage(Model model, Principal principal,HttpSession session){
        if(principal!=null)
            session.setAttribute("nickname",userInfoService.
                    getUserInfo(userAuthService.findUserByPrincipal(principal).getUserUid()).getNickname());
        return "index.html";
    }
}
